#pragma once
#include "ZLabel.h"
#include "ZCaret.h"


namespace ZuiLib
{

class ZTextInput:public ZLabel
{
public:
	ZTextInput(void);
	~ZTextInput(void);

	virtual const char* GetClass() const;
	virtual void* GetInterface(const char* pstrName);

	virtual void DoEvent(TEventUI& event);
	virtual void PaintText(ZRenderer* hDC);
	virtual void SetPos(RECT rc);

	void UpdateScroll();//更新光标
	void UpdateText();

	int CharFromPos(POINT pt);
	POINT PosFromChar(int nCh);

	virtual ZString GetText() const;
	virtual void SetText(const char* pstrText);

	void Copy();
	void Cut();
	void Paste();
	void SelAll();
	void SelNone();

//signal:
	sigslot::signal1<ZTextInput*> SignalTextChanged;

private:
	int GetScrollMax();
	RECT GetCaretRect();
	void SetCaretPos(POINT pt);//设置光标位置

	void RemoveSel();
	void RemoveEditing();

	void PaintTextBk(ZRenderer* render);
	void PaintTextEditing(ZRenderer* render);

	uint32_t m_uButtonState;
	ZCaretPtr m_caret;
	ZWString  m_textUtf16;
	
	//正在编辑的文字
	int m_editingBegin;
	int m_editingEnd;
	int m_editingOffset;

	int m_selBegin;
	int m_selEnd;
	int m_scroll;
	int m_caretPos;
	bool m_needResetText;
};





}